#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;
const int maxn = 1010;

bool a[maxn] = {false} ;
int main()
{
    int n;

    while(scanf("%d", &n) != EOF) {
        int j=0, count = 0, i = 0;
        fill(a, a+1010, false);
        while(count < n) {
            if(a[i] == false) {
               j++;
               if(j==3) {
                   j=0;
                   count++;
                   if(count == n) {
                       cout << i << endl;
                       break;
                   }
                   a[i] = true;
                   //cout << "delete " << i << endl;
               }
            }
            i++;
            if(i == n) i = 0;
        }
    }
    return 0;
}

